#include <stdio.h>
#include <string.h>
#include <math.h>

int n, icase=0;
double a1=0,a2=0,dis=0,pi;
double x,y,z;
double xx,yy,zz,range;


double fu(double x)
{
	return (x/180*pi);
}

main()
{
	int i;
	char name[500];
	double comp;

	while (1)
	{
		scanf("%d%lf%lf%lf", &n, &a1, &a2, &dis);
		if (n==0) break;
		pi=asin(1)*2;

		x=cos(fu(a1))*cos(fu(a2))*(6378+dis);
		y=cos(fu(a1))*sin(fu(a2))*(6378+dis);
		z=sin(fu(a1))*(6378+dis);
		range=(6378+dis)*(6378+dis)-6378*6378;
		
		printf("Test case %d:\n",++icase);
		for (i=1;i<=n;i++)
		{
			scanf("%s%lf%lf", name, &a1, &a2);
			xx=cos(fu(a1))*cos(fu(a2))*(6378);
			yy=cos(fu(a1))*sin(fu(a2))*(6378);
			zz=sin(fu(a1))*(6378);
			comp=(x-xx)*(x-xx)+(y-yy)*(y-yy)+(z-zz)*(z-zz);
			if (comp<range || fabs(comp-range)<1e-8)
				printf("%s\n", name);



		}
		printf("\n");
		

		


		
		
	}

	return 0;
}
